package com.leyou.item.clients;

import com.leyou.common.vo.PageResult;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 连接item-service的接口
 */
@FeignClient("item-service")
public interface ItemClient {

    /**
     * 分页查询spu
     * @param key
     * @param saleable
     * @param page
     * @param rows
     * @return
     */
    @GetMapping("spu/page")
    public PageResult<SpuDTO> querySpuByPage(
            @RequestParam(value = "key", required = false) String key,
            @RequestParam(value = "saleable", required = false) Boolean saleable,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows
    );

    /**
     * 根据id的集合查询商品分类
     * @param ids 商品分类的id集合
     * @return 分类集合
     */
    @GetMapping("category/list")
    public List<CategoryDTO> queryCategoryByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 根据spuId查询对应的sku信息
     */
    @GetMapping("sku/of/spu")
    List<SkuDTO> querySkuBySpuId(@RequestParam("id") Long spuId);

    /**
     * 查询规格参数
     * @param gid
     * @param cid
     * @param searching
     * @return
     */
    @GetMapping("spec/params")
    List<SpecParamDTO> querySpecParams(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching);

    /**
     * 根据spuId查询SpuDetail
     * @param spuId
     * @return
     */
    @GetMapping("spu/detail")
    SpuDetailDTO querySpuDetailBySpuId(@RequestParam("id") Long spuId);

    @GetMapping("brand/list")
    public List<BrandDTO> queryBrandByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 通过id查询spu
     * @param id
     * @return
     */
    @GetMapping("spu/{id}")
    public SpuDTO querySpuById(@PathVariable("id") Long id);

    /**
     * 通过id查询Brand
     * @param id
     * @return
     */
    @GetMapping("brand/brand/{id}")
    public BrandDTO queryBrandById(@PathVariable("id") Long id);

    /**
     * 通过分类cid 查询规格参数
     * @param cid
     * @return
     */
    @GetMapping("spec/of/category")
    public List<SpecGroupDTO> querySpecsByCid(@RequestParam("id") Long cid);

    /**
     * 根据ids 查询 sku的集合
     * @param ids
     * @return
     */
    @GetMapping("sku/list")
    public List<SkuDTO> querySkuIds(@RequestParam("ids") List<Long> ids);

    /**
     * 扣减库存，基于sku的map集合，map的key存放sku的Id，map的value对应的是当前sku应该扣减的数量
     *
     * @param skuMap
     * @return
     */
    @PutMapping("sku/minus")
    Void minusStock(@RequestBody Map<Long, Integer> skuMap);

    /**
     * 加库存，基于sku的map集合，map的key存放sku的Id，map的value对应的是当前sku应该增加的数量
     * @param skuMap
     * @return
     */
    @PutMapping("sku/plus")
    Void plusStock(@RequestBody Map<Long,Integer> skuMap);
}
